package com.ruoyi.web.controller.startplan.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AwPlanConfig;
import com.ruoyi.system.service.IAwPlanConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 启动计划配置Controller
 *
 * @author anxinr
 * @date 2023-08-11
 */
@RestController
@RequestMapping("/awPlan/config")
public class AwPlanConfigController extends BaseController
{
    @Autowired
    private IAwPlanConfigService awPlanConfigService;

    /**
     * 查询启动计划配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwPlanConfig awPlanConfig)
    {
        startPage();
        List<AwPlanConfig> list = awPlanConfigService.selectAwPlanConfigList(awPlanConfig);
        return getDataTable(list);
    }

    /**
     * 导出启动计划配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "启动计划配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AwPlanConfig awPlanConfig)
    {
        List<AwPlanConfig> list = awPlanConfigService.selectAwPlanConfigList(awPlanConfig);
        ExcelUtil<AwPlanConfig> util = new ExcelUtil<AwPlanConfig>(AwPlanConfig.class);
        util.exportExcel(response, list, "启动计划配置数据");
    }

    /**
     * 获取启动计划配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(awPlanConfigService.selectAwPlanConfigById(id));
    }

    /**
     * 新增启动计划配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "启动计划配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwPlanConfig awPlanConfig) throws IOException {
        return toAjax(awPlanConfigService.insertAwPlanConfig(awPlanConfig));
    }

    /**
     * 修改启动计划配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "启动计划配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwPlanConfig awPlanConfig) throws IOException {
        return toAjax(awPlanConfigService.updateAwPlanConfig(awPlanConfig));
    }

    /**
     * 删除启动计划配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "启动计划配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(awPlanConfigService.deleteAwPlanConfigByIds(ids));
    }


}
